package com.czy.workflow.core.service.dao;

import com.czy.workflow.core.model.FlowNode;
import com.czy.workflow.core.model.OperationType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface NodeRepository extends JpaRepository<FlowNode, String> {

    @Query("select n from FlowBranch b, FlowNode n where b.sourceNodeId = ?1 and b.targetNodeId = n.id")
    List<FlowNode> findNextNodes(String sourceId);

    @Query("select n from FlowRuntimeNode rn, FlowNode n where rn.docId = ?1 and rn.nodeId = n.id")
    List<FlowNode> findCurrentNodes(String docId);

    @Query("select n from FlowRuntimeNode rn, FlowNode n where rn.nodeId = n.id")
    List<FlowNode> findRuntimeNodes();

    List<FlowNode> findByFlowIdAndOperationType(String flowId, OperationType operationType);

}
